package com.gwclh.personnel.controller;


import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.domain.PageDomain;
import com.gwclh.personnel.entity.EmpInfo;
import com.gwclh.personnel.entity.User;
import com.gwclh.personnel.service.IEmpInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 员工信息中心，有更详细的信息
 * 前端控制器
 * </p>
 *
 * @author gzhhh
 * @since 2020-07-24
 */
@RestController
@RequestMapping("/emp-infos")
public class EmpInfoController extends BaseController {
    @Autowired
    IEmpInfoService empInfoService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询就业信息")
    public ResultVo getEmpInfoById(@PathVariable(value = "id") Integer id) {
        EmpInfo empInfo = empInfoService.getOne(new QueryWrapper<EmpInfo>().eq("emp_id", id));
        return ResultVo.success(empInfo);
    }

    @PostMapping("")
    @ApiOperation(value = "根据员工id查询保存或添加就业信息")
    public ResultVo saveOrUpdateEmpInfo(@Validated @RequestBody EmpInfo empInfo) {
        EmpInfo e = empInfoService.getOne(new QueryWrapper<EmpInfo>().eq("emp_id", empInfo.getEmpId()));
        if (e != null) {
            boolean b = empInfoService.updateById(empInfo);
            Assert.isTrue(b, "保存失败！");
        } else {
            boolean save = empInfoService.save(empInfo);
            Assert.isTrue(save, "保存失败！");
        }
        return ResultVo.success();
    }
}